package china.lzy.controller;

import china.lzy.api.GoodsControllerApi;
import china.lzy.entity.ResResult;
import china.lzy.entity.dto.PageDto;
import china.lzy.entity.pojo.Goods;
import china.lzy.service.GoodsService;
import china.lzy.utils.anno.Authorization;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lzy
 * @description goods
 * @date 2021-08-16
 */
@RestController
@RequestMapping(value = "/goods")
public class GoodsController implements GoodsControllerApi {

    @Resource
    private GoodsService goodsService;

    /**
     * 新增
     *
     * @author lzy
     * @date 2021/08/16
     **/
    @Authorization({"admin"})
    @PostMapping("/insert")
    public ResResult insert(@RequestBody Goods goods) {
        return goodsService.insert(goods);
    }

    /**
     * 刪除
     *
     * @author lzy
     * @date 2021/08/16
     **/
    @Authorization({"admin"})
    @PostMapping("/delete/{id}")
    public ResResult delete( @PathVariable int id) {
        return goodsService.delete(id);
    }

    /**
     * 更新
     *
     * @author lzy
     * @date 2021/08/16
     **/
    @Authorization({"admin"})
    @PostMapping("/update")
    public ResResult update(@RequestBody Goods goods) {
        return goodsService.update(goods);
    }

    /**
     * 查询 根据主键 id 查询
     *
     * @author lzy
     * @date 2021/08/16
     **/
    @Authorization({"admin"})
    @PostMapping("/load/{id}")
    public ResResult load(@PathVariable int id) {
        return goodsService.load(id);
    }

    /**
     * 查询 分页查询
     *
     * @author lzy
     * @date 2021/08/16
     **/
    @Authorization({"admin"})
    @PostMapping("/pageList")
    public ResResult pageList(@RequestBody PageDto page) {
        return goodsService.pageList(page);
    }

}